<template>
  <Edialog
    title="访问管理端（运营管理系统）"
    :outershow="dialogShow"
    @close="close"
    width="60%"
  >
    <ETable
      :ifShowPagination="false"
      ref="ETable"
      :height="280"
      :titleObj="titleObj"
      operateWidth="90"
      :reqObj="setOf"
      :reqFn="getSysSystemAccess"
      :page="pageInfo"
    >
      <template v-slot="{ scope }">
        <el-button
          v-if="scope.IS_ENABLE == 1"
          @click="stateFn(scope)"
          type="text"
          size="small"
          >禁用</el-button
        >
        <el-button v-else @click="stateFn(scope)" type="text" size="small"
          >启用</el-button
        >
      </template>
    </ETable>
  </Edialog>
</template>

<script>
import ETable from '@/components/ETable'
import Edialog from '@/components/Edialog'
import { getSysSystemAccess, postDoEnableOrStop } from '@/api/management/system'
export default {
  name: 'SystemEdit',
  components: {
    ETable,
    Edialog
  },
  data () {
    return {
      dialogShow: false,
      titleObj: [
        { prop: 'ACCESS_TYPE_NAME', label: '访问端类型', width: '100' },
        { prop: 'ADDRESS', label: '系统访问地址', minWidth: '200' },
        {
          prop: 'IS_ENABLE',
          label: '启用状态',
          width: '90',
          formatter: scope => this.fmIsEnable(scope)
        }
      ],
      setOf: {
        systemCode: ''
      },
      pageInfo: {
        page: 1,
        size: 99999,
        total: 0,
        sizes: [20, 50, 100, 500, 1000]
      }
    }
  },
  methods: {
    getSysSystemAccess,
    async open (row) {
      this.setOf.systemCode = row.SYSTEM_CODE
      this.dialogShow = true
      this.$nextTick(() => {
        this.$refs.ETable.pageInfo.page = 1
        this.$refs.ETable.getData()
      })
    },
    fmIsEnable (scope) {
      return <span>{scope.IS_ENABLE == 1 ? '启用' : '禁用'}</span>
    },
    async stateFn (row) {
      let t = await this.$confirm(
        `此操作将永久${row.IS_ENABLE == 1 ? '禁用' : '启用'}, 是否继续?`,
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
      if (t) {
        let res = await postDoEnableOrStop(row.ID)
        if (res.data && res.data.bcode == 0) {
          this.$message.success('操作成功')
          row.IS_ENABLE = row.IS_ENABLE == 1 ? 0 : 1
        }
      }
    },
    close () {
      this.dialogShow = false
    }
  }
}
</script>

<style scoped lang="scss"></style>
